package com.ysd.crm.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.gson.Gson;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@Component
/** * 处理结果 * @author Administrator * */
@ApiModel("处理结果")
public class Result {
	@Autowired
	private static Gson t = new Gson();
	
	@ApiModelProperty("是否成功")
	public boolean success;
	@ApiModelProperty("信息消息")
	public String message;
	@ApiModelProperty("标记")
	public String remark;

	public static Result toClient(boolean suc, Object msg) {
		Result r = new Result();
		r.success = suc;
		r.message = msg.toString();
		r.remark = "";
		return r;
	}
	
	public static Result toClient(boolean suc, Object msg, String remark) {
		Result r = new Result();
		r.success = suc;
		r.message = msg.toString();
		r.remark = remark;
		return r;
	}
	public static String toClientJson(boolean suc, Object msg) {
		Result r = new Result();
		r.success = suc;
		r.message = msg.toString();
		r.remark = "";
		return t.toJson(r);
	}
	
	public static String toClientJson(boolean suc, Object msg, String remark) {
		Result r = new Result();
		r.success = suc;
		r.message = msg.toString();
		r.remark = remark;
		return t.toJson(r);
	}
		public static String toJsonClient(boolean suc, Object msg) {
			Result r = new Result();
			r.success = suc;
			r.message = msg.toString();
			r.remark = "";
//			Gson t = new Gson();
			return t.toJson(r);
		}
		//加了static的方法,可以直接通过"类名.方法名()"来进行调用,Result.toCline(true,"成功","")
		public static String toJsonClient(boolean suc, Object msg, String remark) {
			Result r = new Result();
			r.success = suc;
			r.message = msg.toString();
			r.remark = remark;
//			Gson t = new Gson();
			return t.toJson(r);
		}
	
	public static String toJson(Object toJsonObject) {
//		Gson t = new Gson();
		return t.toJson(toJsonObject);
	}
}
